/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ventas.dao;

import com.ventas.bean.Categoria;
import com.ventas.service.CategoriaInterfaz;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author jesus
 */
public class CategoriaDao implements CategoriaInterfaz{

    @Override
    public List obtener() throws Exception {
        List<Categoria> listadoCat = new ArrayList();
        Connection con = null;
        CallableStatement cstm = null;
        ResultSet rs = null;
        try {
            con = Conexion.getConexion();
            String sql="CALL pa_selectCategoria()"; 
            cstm = con.prepareCall(sql);
            rs = cstm.executeQuery();
            while(rs.next()){
            Categoria categoria = new Categoria();
            
            
            categoria.setCat_id(rs.getInt(1));
            categoria.setCat_descripcion(rs.getString(2));
                System.out.println("Categoria id"+ categoria.getCat_id());
                System.out.println("Nombre" + categoria.getCat_descripcion());
                listadoCat.add(categoria);
            
            }
            System.out.println("Exito carga SelectMaterialDao");
        } catch (Exception e) {
            System.out.println("Error carga SelectMaterialDao");
            e.printStackTrace();
        }finally{
        rs.close();
        cstm.close();
        con.close();
        }
        return listadoCat;

 
    }
    }
    

